package org.yin.hang.controller;


import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.yin.hang.dao.duanxinDao;

import org.yin.hang.pojo.duanxin;
import org.yin.hang.utils.ResponseResult;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/duanxin")
@CrossOrigin("*")
public class duanxiunController {

    @Autowired
    private duanxinDao duanxinDao;


    @RequestMapping("/list")
    @ResponseBody
    public ResponseResult<List<duanxin>> list(@RequestParam(defaultValue = "1") int page, @RequestParam(defaultValue = "10") int limit, duanxin condition) throws Exception {
        Map<String,Object> map = new HashMap<>();


        Page<duanxin> pager = PageHelper.startPage(page, limit);
        List<duanxin> list = duanxinDao.getConditionList(condition);


        return new ResponseResult(pager.getTotal(),list);
    }

    @RequestMapping("/delete")
    @ResponseBody
    public ResponseResult delete(int dx_Id) throws Exception{
        duanxinDao.delete(dx_Id);
        return ResponseResult.createSuccessResult();
    }

    @RequestMapping("/add")
    @ResponseBody
    public ResponseResult add(duanxin duanxin) throws Exception{
        duanxinDao.add(duanxin);
        return ResponseResult.createSuccessResult();
    }

    @RequestMapping("/edit")
    @ResponseBody
    public ResponseResult edit(duanxin duanxin) throws Exception{
        duanxinDao.update(duanxin);
        return ResponseResult.createSuccessResult();
    }
}
